package rkdwogus7.basic;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class J23_MemberDAO implements J23_MemberService {
	
	private static final String DRV = "oracle.jdbc.OracleDriver";
	private static final String URL = "jdbc:oracle:thin:@//localhost:1521/xe";
	private static final String USR = "scott";
	private static final String PWD = "TIGER";
	
	private static final String selectSQL = "select * from member order by userid asc";
	private static final String selectOneSQl =
			"select * from member where userid = ?";
	private static final String insertSQL =
			"insert into member(userid, jumin, pwd, zip, addr, tel, mp, pay) "
			+ " values( ?, ?, ?, ?, ?, ?, ?, ?) ";
	
	@Override
	public int insertJ23_Member(J23_Member m) {
		int cnt = 0;
		
		return cnt;
	}

	@Override
	public int updateJ23_Member(J23_Member m) {
		int cnt = 0;
		
		return cnt;

	}
	@Override
	public int deleteJ23_Member(String m) {
		int cnt = 0;
		
		return cnt;

	}
	@Override
	public ArrayList<J23_Member> selectMember() {
		ArrayList<J23_Member> data = new ArrayList<>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			Class.forName(DRV);
			conn = DriverManager.getConnection(URL, USR, PWD);
			ps = conn.prepareStatement(selectSQL);
			rs = ps.executeQuery();
			while (rs.next()) {
				J23_Member m =
						new J23_Member(rs.getString(1), rs.getString(2),
									"", "", "", "", rs.getString(3), "");
				// 결과 집합 rs에 저장된 모든 데이터 중
				// 레코드 단위(행)로 하나씩 읽어와서
				// ArraList인 data에 추가함
				data.add(m);
			}
			
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (rs != null) {
				try { rs.close(); } catch (Exception e) { }
			}
			if (ps != null) {
				try { ps.close(); } catch (Exception e) { }
			}
			if (conn != null) {
				try { conn.close(); } catch (Exception e) { }
			}
		}
		
		
		return data;
	}
	@Override
	public J23_Member selectOneMember(String m) {
		J23_Member data = null;
		
		return data;
	}
	
	


}
